package cn.zhanghu;

/**
 * Created by dell on 2017/7/5.
 */
public class QuickSort {
    public static int merge(int[] array, int left, int right){
        //int i=left;
        //int j=right;
        int temp=array[left];
        while(left<right) {
            while (left < right && array[right] >= temp && right > 0) {
                right--;
            }
            array[left] = array[right];
            while(left<right&&array[left]<=temp){
                left++;
            }
            array[right]=array[left];
        }
        array[left]=temp;
        return left;
    }

    public static int[] sort(int[] array, int left, int right){
        if(left<right){
            int middle=merge(array,left,right);
            sort(array,left,middle-1);
            sort(array,middle+1,right);
        }
        return array;
    }

    public static void result(int[] result){
        System.out.println("result is : ");
        for(int value:result){
            System.out.print(""+value+" ");
        }
    }


}
